{extend name="index_layout"/}
{block name="main"}
<form class="layui-form" id="c" method="post">

    <div class="layui-form-item">
        <label class="layui-form-label">商品分类</label>
        <div class="layui-input-block">
            <select name="cate_id" >
                <option>请选择商品分类</option>
                {volist name="goods_cate" id="vo"}
                <option value="{$vo.id}" <?php if( $vo['id'] == $data['goods_cate_id']){ ?> selected <?php }?>>{$vo.name}</option>
                {/volist}
            </select>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">品牌</label>
        <div class="layui-input-block">
            <select name="brand_id" >
                <option>请选择商品品牌</option>
                {volist name="brand" id="vo"}
                <option value="{$vo.id}" <?php if( $vo['id'] == $data['brand_id']){ ?> selected <?php }?>>{$vo.name}</option>
                {/volist}
            </select>
        </div>
    </div>

<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">发货方式</label>-->
<!--        <div class="layui-input-block" id="is_c3">-->
<!--            <input type="radio" name="delivery_type"  checked value="1" title="全部" lay-filter="ccc3">-->

<!--            <input type="radio" name="delivery_type"   value="2" title="仅邮寄" lay-filter="ccc3">-->

<!--            <input type="radio" name="delivery_type"   value="3" title="仅自提" lay-filter="ccc3">-->
<!--        </div>-->
<!--    </div>-->

    <div class="layui-form-item">
        <label class="layui-form-label">供应商</label>
        <div class="layui-input-block">
            <select name="supply_id">
                <option>请选择供应商</option>
                {volist name="supply" id="vo"}
                <option value="{$vo.id}" <?php if( $vo['id'] == $data['supply_id']){ ?> selected <?php }?>>{$vo.nickname}</option>
                {/volist}
            </select>
        </div>
    </div>

<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">店家核销奖励(%)</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input type="text" name="shop_return" value="{$data.shop_return}"   lay-verify="required|number" autocomplete="off"-->
<!--                   placeholder="店家核销奖励(%)"-->
<!--                   class="layui-input">-->
<!--        </div>-->
<!--    </div>-->

    <div class="layui-form-item">
        <label class="layui-form-label">商品名称</label>
        <div class="layui-input-block">
            <input type="text" name="name" value="{$data.name}" lay-verify="required" autocomplete="off"
                   placeholder="商品名称"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">简介</label>
        <div class="layui-input-block">
            <textarea name="desc" placeholder="简介" class="layui-textarea">{$data.desc}</textarea>
        </div>
    </div>
<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">单位</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input type="text" name="unit" value="{$data.unit}" lay-verify="required" autocomplete="off" placeholder="单位"-->
<!--                   class="layui-input">-->
<!--        </div>-->
<!--    </div>-->

    <div class="layui-form-item c4">
        <label class="layui-form-label">图片</label>
        <div class="layui-input-block">
            <input type="text" name="img" id="c-pic" value="{$data.img}" class="layui-input">
        </div>
        <div class="layui-input-block">
            <button type="button" class="layui-btn faupload" id="faupload-pic" data-multiple="true" data-input-id="c-pic"
                    data-preview-id="p-pic" data-type="image"><i class="layui-icon layui-icon-upload"></i> 上传
            </button>
            <button type="button" class="layui-btn fachoose" data-multiple="true" data-mimetype="image"
                    data-input-id="c-pic" id="fachoose-c-pic"><i class="iconfont icon-other"></i> 选择
            </button>
            <ul class="layui-row list-inline plupload-preview" id="p-pic"></ul>
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">商品规格</label>
        <div class="layui-input-block" id="is_c">
            <input type="radio" name="is_spec" value="0" title="单规格" checked lay-filter="ccc">
            <input type="radio" name="is_spec" value="1" title="多规格" lay-filter="ccc">
        </div>
    </div>



    <!--    <div class="layui-form-item is_limit" style="display: none;">-->
    <!--        <label class="layui-form-label">最低消费(最低消费填写)</label>-->
    <!--        <div class="layui-input-block">-->
    <!--            <input type="number" name="min_amount" value="0.00" lay-verify="required"  autocomplete="off" placeholder="最低消费"-->
    <!--                   class="layui-input" step="0.01">-->
    <!--        </div>-->
    <!--    </div>-->
    <div class="layui-form-item spec_button" id="c11" style="display: none;">
        <div class="layui-input-block">
            <!--            <button type="button" class="layui-btn layui-btn-sm" onclick="addSpec(this)">添加新规格</button>-->
            <button type="button" class="layui-btn layui-btn-sm" onclick="addSpec(this)">生成</button>
        </div>
    </div>

    <div class="layui-form-item spec_input" style="display: none;">
        <label class="layui-form-label">规格/规格值</label>
        <div class="layui-input-block">
            <input id="spec_name" style="float: left;width: 300px; margin-right: 20px" type="text" name="attr_name"
                   value="{$data.spec_name}" autocomplete="off" placeholder="规格"
                   class="layui-input">
            <input id="spec_value" style="float: left;width: 300px;" type="text" name="attr_value" value="{$data.spec_value}"
                   autocomplete="off" placeholder="规格值（例最多4个）:s,xl,xxl,xxxl"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item ">
        <div class="layui-input-block">
            <div style="float: left;width: 40px; margin-right: 10px;background-color: #00a0e9;padding: 5px;text-align: center;color: white;font-weight: bold">
                规格
            </div>
            <div style="float: left;width: 110px; margin-right: 10px;background-color: #00a0e9;padding: 5px;text-align: center;color: white;font-weight: bold">
                售价
            </div>
<!--            <div style="float: left;width: 110px; margin-right: 10px;background-color: #00a0e9;padding: 5px;text-align: center;color: white;font-weight: bold">-->
<!--                助力价-->
<!--            </div>-->
            <div style="float: left;width: 110px; margin-right: 10px;background-color: #00a0e9;padding: 5px;text-align: center;color: white;font-weight: bold">
                原价
            </div>
<!--            <div style="float: left;width: 110px; margin-right: 10px;background-color: #00a0e9;padding: 5px;text-align: center;color: white;font-weight: bold">-->
<!--                供货商回款-->
<!--            </div>-->
            <div style="float: left;width: 110px; margin-right: 10px;background-color: #00a0e9;padding: 5px;text-align: center;color: white;font-weight: bold">
                库存
            </div>
        </div>
    </div>
    <div id="spec_detail1">
        <div class="layui-form-item ">
            <div class="layui-input-block">
                <input readonly="readonly" style="float: left;width: 50px; margin-right: 10px" type="text" name="spec_name"   value='默认' autocomplete="off" placeholder="规格" class="layui-input">
                <input lay-verify="required" style="float: left;width: 120px; margin-right: 10px" type="text"
                       name="price" value="{$data.name}" autocomplete="off" placeholder="售价"
                       class="layui-input">

<!--                <input lay-verify="required" style="float: left;width: 120px; margin-right: 10px" type="text"-->
<!--                       name="spec[{$k}][pin_price]" value="{$vo['pin_price']}" autocomplete="off" placeholder="助力价"-->
<!--                       class="layui-input">-->

                <input lay-verify="required" style="float: left;width: 120px; margin-right: 10px" type="text"
                       name="old_price" value="{$data.name}" autocomplete="off" placeholder="原价"
                       class="layui-input">


<!--                <input lay-verify="required" style="float: left;width: 120px; margin-right: 10px" type="text"-->
<!--                       name="gong_price" value="{$data.name}" autocomplete="off" placeholder="供货商回款"-->
<!--                       class="layui-input">-->

                <input lay-verify="required" style="float: left;width: 120px;" type="text" value="100"
                       name="stock" autocomplete="off" placeholder="库存"
                       class="layui-input">
            </div>
        </div>
    </div>
    <div id="spec_detail">

    </div>

    <div class="layui-form-item" >
        <label class="layui-form-label">内容详情</label>
        <div class="layui-input-block">
            <script type="text/plain" class="js-ueditor" name="detail"
                    style="position: relative;z-index: 1 !important;"
                    id="content">{$data['detail']|default=''|raw}</script>
        </div>
    </div>



    <div class="layui-form-item">
        <label class="layui-form-label">排序</label>
        <div class="layui-input-block">
            <input type="text" name="sort" value="{$data.sort}" value="1" lay-verify="required|number" autocomplete="off"
                   placeholder="排序"
                   class="layui-input">
        </div>
    </div>

<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">化妆品备案号</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input type="text" name="hz_no" value="{$data.hz_no}" lay-verify="required" autocomplete="off" placeholder="化妆品备案号"-->
<!--                   class="layui-input">-->
<!--        </div>-->
<!--    </div>-->

<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">注册证号</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input type="text" name="zc_no" value="{$data.zc_no}" lay-verify="required" autocomplete="off" placeholder="注册证号"-->
<!--                   class="layui-input">-->
<!--        </div>-->
<!--    </div>-->


<!--    <div class="layui-form-item">-->
<!--        <label class="layui-form-label">产品功效</label>-->
<!--        <div class="layui-input-block">-->
<!--            <input type="text" name="effect" value="{$data.effect}" lay-verify="required" autocomplete="off" placeholder="产品功效"-->
<!--                   class="layui-input">-->
<!--        </div>-->
<!--    </div>-->

    <div class="layui-form-item">
        <label class="layui-form-label">保质期</label>
        <div class="layui-input-block">
            <input type="text" name="quality" value="{$data.quality}" lay-verify="required" autocomplete="off" placeholder="保质期"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">产地</label>
        <div class="layui-input-block">
            <input type="text" name="product_address" value="{$data.product_address}" lay-verify="required" autocomplete="off" placeholder="产地"
                   class="layui-input">
        </div>
    </div>
    <div class="layui-form-item">
        <label class="layui-form-label">发货地</label>
        <div class="layui-input-block">
            <input type="text" name="send_address" value="{$data.send_address}" lay-verify="required" autocomplete="off" placeholder="发货地"
                   class="layui-input">
        </div>
    </div>

    <div class="layui-form-item">
        <label class="layui-form-label">保障说明</label>
        <div class="layui-input-block">
            <textarea name="guarantee" placeholder="保障说明" class="layui-textarea">{$data.guarantee}</textarea>
        </div>
    </div>



    <div class="layui-form-item layer-footer">
        <div class="layui-input-block">
            <button class="layui-btn" lay-submit="">立即提交</button>
            <button type="reset" class="layui-btn layui-btn-primary">重置</button>
        </div>
    </div>
</form>
{/block}
{block name="script"}
<script type="text/javascript">
    layui.use(['yznForm', 'form'], function () {
        var yznForm = layui.yznForm;
        var form = layui.form;
        yznForm.bindevent($("form.layui-form"));

        form.on('radio(ccc)', function (data) {
            console.log(data.value)
            if (data.value == 0) {
                $(".spec_button").hide();
                $(".spec_input").hide();
                $("#spec_detail").empty();
                var str="        <div class=\"layui-form-item \">\n" +
                    "            <div class=\"layui-input-block\">\n" +
                    "                <input readonly=\"readonly\" style=\"float: left;width: 50px; margin-right: 10px\" type=\"text\" name=\"spec_name\"   value='默认' autocomplete=\"off\" placeholder=\"规格\" class=\"layui-input\">\n" +
                    "                <input lay-verify=\"required\" style=\"float: left;width: 120px; margin-right: 10px\" type=\"text\"\n" +
                    "                       name=\"price\" value=\"{$data.name}\" autocomplete=\"off\" placeholder=\"售价\"\n" +
                    "                       class=\"layui-input\">\n" +
                    // "                <input lay-verify=\"required\" style=\"float: left;width: 120px; margin-right: 10px\" type=\"text\"\n" +
                    // "                       name=\"pin_price\" value=\"{$data.name}\" autocomplete=\"off\" placeholder=\"助力价\"\n" +
                    // "                       class=\"layui-input\">\n"+
                    "                <input lay-verify=\"required\" style=\"float: left;width: 120px; margin-right: 10px\" type=\"text\"\n" +
                    "                       name=\"old_price\" value=\"{$data.name}\" autocomplete=\"off\" placeholder=\"原价\"\n" +
                    "                       class=\"layui-input\">\n" +
                    // "                <input lay-verify=\"required\" style=\"float: left;width: 120px; margin-right: 10px\"  type=\"text\" \n" +
                    // "                       name=\"gong_price\" autocomplete=\"off\" placeholder=\"供货商回款\"\n" +
                    // "                       class=\"layui-input\">\n"+
                    "                <input lay-verify=\"required\" style=\"float: left;width: 120px;\" type=\"text\" value=\"100\"\n" +
                    "                       name=\"stock\" autocomplete=\"off\" placeholder=\"库存\"\n" +
                    "                       class=\"layui-input\">\n" +
                    "            </div>\n" +
                    "        </div>";
                $("#spec_detail").empty();
                $("#spec_detail1").append(str);
            } else {
                $(".spec_button").show();
                $(".spec_input").show();
                $("#spec_detail1").empty();
            }
            form.render();
        });

    });

    function addSpec(data) {
        var spec_name = document.getElementById("spec_name").value;
        var spec_value = document.getElementById("spec_value").value;
        if (spec_name && spec_value) {
            $("#spec_detail").empty();
            spec_value = spec_value.split(",");
            var str = '';
            $.each(spec_value, function (i, val) {
                str += '  <div class="layui-form-item ">\n' +
                    '            <div class="layui-input-block" >' +
                    '<input readonly="readonly" style="float: left;width: 50px; margin-right: 10px" type="text" name="spec[' + i + '][spec_name]"   value=' + val + ' autocomplete="off" placeholder="规格"\n' +
                    'class="layui-input">    ' +
                    '<input lay-verify="required"   style="float: left;width: 120px; margin-right: 10px" type="text" name="spec[' + i + '][price]"   value="{$data.name}" autocomplete="off" placeholder="售价"\n' +
                    '                         class="layui-input">\n' +
                    // '<input lay-verify="required"   style="float: left;width: 120px; margin-right: 10px" type="text" name="spec[' + i + '][pin_price]"   value="{$data.name}" autocomplete="off" placeholder="助力价"\n' +
                    // '                         class="layui-input">\n'+
                    '                <input lay-verify="required"   style="float: left;width: 120px; margin-right: 10px" type="text" name="spec[' + i + '][old_price]"  value="{$data.name}" autocomplete="off" placeholder="原价"\n' +
                    '                         class="layui-input">\n' +
                    // '                <input lay-verify="required"   style="float: left;width: 120px; margin-right: 10px"   type="text"   name="spec[' + i + '][gong_price]" autocomplete="off" placeholder="供货商回款"\n' +
                    // '                         class="layui-input">\n'+
                    '                <input lay-verify="required"   style="float: left;width: 120px; margin-right: 10px"   type="text"  value="100"  name="spec[' + i + '][stock]" autocomplete="off" placeholder="库存"\n' +
                    '                         class="layui-input">\n' +
                    '\n' +
                    '            </div>\n' +
                    '        </div>'
                console.log(i, val);
            });
            $("#spec_detail").append(str);
            layui.form.render();
            console.log(str);
        } else {
            layer.msg('请填写规格值！');
        }
        console.log(spec_name);
        console.log(spec_value);
    }
</script>
{/block}